package protocol.SZ_2021;

import java.util.HashMap;

public class Handle2021SZ0B implements IHandle2021SZ {
    @Override
    public String handle(SZ_2021Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x01:
                return handle0B01(cmd);
            case 0x03:
                return handle0B03(cmd);
            case 0x04:
                return handle0B04(cmd);
            case 0x05:
                return handle0B05(cmd);
            case 0x07:
                return handle0B07(cmd);
            case 0x08:
                return handle0B08(cmd);
            case 0x10:
                return handle0B10(cmd);
            case 0x11:
                return handle0B11(cmd);
            case 0x71:
                return handle0B71(cmd);
            case (byte) 0xF5:
                return handle0BF5(cmd);
            default:
                return "深标:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }

    private String handle0B71(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:打印状态上报");
        builder.append("\r\n");
        builder.append("时间:"+cmd.readBCD(6));
        builder.append("\r\n");
        builder.append("营运ID:"+cmd.readInt(4));
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"未打印发票");
        list.put(1,"打印过发票");
        builder.append("打印状态:"+list.getOrDefault(cmd.readInt(),"未定义"));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle0B11(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:设备巡检应答");
        builder.append("\r\n");

        do{
            builder.append("终端设备序列号:"+cmd.readBCD(5));
            builder.append("\r\n");
            builder.append("硬件版本号:"+cmd.readBCD(1));
            builder.append("\r\n");
            builder.append("软件版本号:"+cmd.readBCD(2));
            builder.append("\r\n");
            builder.append("终端设备状态:"+cmd.readInt(4));
            builder.append("\r\n");
            builder.append("终端报警标志:"+cmd.readInt(4));
            builder.append("\r\n");

            builder.append("签到缓存数据条数:"+cmd.readInt());
            builder.append("\r\n");
            builder.append("签退缓存数据条数:"+cmd.readInt());
            builder.append("\r\n");
            builder.append("营运记录缓存条数:"+cmd.readInt());
            builder.append("\r\n");
            builder.append("IC卡交易缓存条数:"+cmd.readInt());
            builder.append("\r\n");

            builder.append("人机交互设备硬件版本号:"+cmd.readBCD(1));
            builder.append("\r\n");

            builder.append("人机交互设备软件版本号:"+cmd.readBCD(2));
            builder.append("\r\n");

            builder.append("人机交互设备状态:"+(cmd.readInt() == 0?"正常":"异常"));
            builder.append("\r\n");
            builder.append("-----------------");
            builder.append("\r\n");
        }while (cmd.leftSize() > 10);

        return builder.toString();
    }

    private String handle0B10(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:外围设备指令上行透传");
        builder.append("\r\n");

        int dev = cmd.readInt(1);
        builder.append("设备类型:"+ SZ_2021Utils.toDeviceType(dev));
        builder.append("\r\n");

        builder.append("厂商标识:"+cmd.readInt(1));
        builder.append("\r\n");

        builder.append("命令类型:"+cmd.readBCD(2));
        builder.append("\r\n");

        builder.append("数据包:"+cmd.readBCD(cmd.leftSize()));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle0BF5(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:运营数据里程作弊检查");
        builder.append("\r\n");

        builder.append("营运数据："+cmd.readBCD(170));
        builder.append("\r\n");
        builder.append("CAN计算营运里程（米）："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("CAN计算空车里程（米）："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("CAN计算计时时间："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("CAN计算交易金额（分）："+cmd.readBCD(3));
        builder.append("\r\n");

        builder.append("GPS计算营运里程（米）："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("GPS计算空车里程（米）："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("GPS计算计时时间："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("GPS计算交易金额（分）："+cmd.readBCD(3));
        builder.append("\r\n");

        builder.append("脉冲计算营运里程（米）："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("脉冲计算空车里程（米）："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("脉冲计算计时时间："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("脉冲计算交易金额（分）："+cmd.readBCD(3));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle0B04(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:下班签退信息上传");
        builder.append("\r\n");

        SZ_2021Utils.handle0200Base(cmd,builder);

        builder.append("单位代码:"+cmd.readString(16));
        builder.append("\r\n");

        builder.append("司机代码:"+cmd.readString(19));
        builder.append("\r\n");

        builder.append("车牌号:"+cmd.readString(9));
        builder.append("\r\n");

        builder.append("K值:"+cmd.readBCD(2));
        builder.append("\r\n");

        builder.append("当班开机时间:"+cmd.readBCD(7));
        builder.append("\r\n");
        builder.append("当班关机时间:"+cmd.readBCD(7));
        builder.append("\r\n");
        builder.append("当班公里(xx.x公里):"+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("当班营运公里(xx.x公里):"+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("当班车次:"+cmd.readBCD(2));
        builder.append("\r\n");
        builder.append("计时时间:"+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("总计金额（格式XXXXX.X元）:"+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("卡收金额（格式XXXXX.X元）:"+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("卡次:"+cmd.readBCD(2));
        builder.append("\r\n");

        builder.append("班间公里(xx.x公里):"+cmd.readBCD(2));
        builder.append("\r\n");
        builder.append("总计公里(xx.x公里):"+cmd.readBCD(4));
        builder.append("\r\n");
        builder.append("总营运公里(xx.x公里):"+cmd.readBCD(4));
        builder.append("\r\n");
        builder.append("单价(格式XX.XX元):"+cmd.readBCD(2));
        builder.append("\r\n");
        builder.append("总营运次数:"+cmd.readInt(4));
        builder.append("\r\n");

        int type = cmd.readInt(1);
        HashMap<Integer,String> list = new HashMap<>();
        list.put(0x01,"驾驶员手工签退");
        list.put(0x02,"自动签退");
        list.put(0x03,"锁表签退");
        list.put(0x04,"强制签退");
        list.put(0x05,"远程签退");
        builder.append("签退类型("+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        builder.append("发票张数:"+cmd.readInt(2));
        builder.append("\r\n");
        return builder.toString();
    }

    private String handle0B03(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:上班签到信息上传");
        builder.append("\r\n");

        SZ_2021Utils.handle0200Base(cmd,builder);

        builder.append("单位代码:"+cmd.readString(16));
        builder.append("\r\n");

        builder.append("司机代码:"+cmd.readString(19));
        builder.append("\r\n");

        builder.append("车牌号:"+cmd.readString(9));
        builder.append("\r\n");

        builder.append("计程计价装置开机时间:"+cmd.readBCD(7));
        builder.append("\r\n");

        builder.append("总营运次数:"+cmd.readInt(4));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle0B08(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:驾驶员取消订单");
        builder.append("\r\n");
        builder.append("业务ID:"+cmd.readInt(4));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle0B07(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:驾驶员电召任务完成确认");
        builder.append("\r\n");
        builder.append("业务ID:"+cmd.readInt(4));
        builder.append("\r\n");
        return builder.toString();
    }


    private String handle0B01(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:驾驶员订单抢答");
        builder.append("\r\n");
        builder.append("业务ID:"+cmd.readInt(4));
        builder.append("\r\n");
        return builder.toString();
    }

    private String handle0B05(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:运营数据上传");
        builder.append("\r\n");
        builder.append("空转重位置信息：");
        builder.append("\r\n");
        SZ_2021Utils.handle0200Base(cmd,builder);

        builder.append("重转空位置信息：");
        builder.append("\r\n");
        SZ_2021Utils.handle0200Base(cmd,builder);

        builder.append("营运ID："+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("评价ID："+cmd.readInt(4));
        builder.append("\r\n");

        int type = cmd.readInt(1);
        HashMap<Integer,String> list = new HashMap<>();
        list.put(0x00,"没有做出评价");
        list.put(0x01,"满意");
        list.put(0x02,"一般");
        list.put(0x03,"不满意");
        builder.append("评价选项("+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        builder.append("载客人数:"+cmd.readInt(2));
        builder.append("\r\n");
        builder.append("订单ID:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("VST估算里程(米):"+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("计程计价装置营运数据:");
        builder.append("\r\n");

        builder.append("    车牌号："+cmd.readString(9));
        builder.append("\r\n");
        builder.append("    经营许可证号："+cmd.readString(16));
        builder.append("\r\n");
        builder.append("    从业资格证号："+cmd.readString(19));
        builder.append("\r\n");
        builder.append("    开始时间（年月日时分秒）："+cmd.readBCD(7));
        builder.append("\r\n");
        builder.append("    结束时间（月日时分秒）："+cmd.readBCD(5));
        builder.append("\r\n");
        builder.append("    营运结束单价（分）："+cmd.readBCD(2));
        builder.append("\r\n");
        builder.append("    营运里程（米）："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("    空车里程（米）："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("    计时时间："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("    交易金额（分）："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("    附加费（分）："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("    电召费（分）："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("    当前车次："+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("    空车断电次数："+cmd.readBCD(2));
        builder.append("\r\n");
        builder.append("    空车断电时间："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("    超速里程："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("    超速次数："+cmd.readBCD(2));
        builder.append("\r\n");
        builder.append("    超极速次数："+cmd.readBCD(2));
        builder.append("\r\n");
        builder.append("    作弊次数："+cmd.readBCD(2));
        builder.append("\r\n");

        int type2 = cmd.readInt(1);
        list.clear();
        list.put(0,"现金交易");
        list.put(1,"银联卡交易");
        list.put(2,"深圳通卡");
        list.put(3,"八达通");
        list.put(4,"羊城通");
        list.put(5,"微信");
        list.put(6,"支付宝");

        builder.append("    交易卡类型("+type2+")："+list.getOrDefault(type2,"未定义"));
        builder.append("\r\n");

        builder.append("    交易卡号："+cmd.readBCD(10));
        builder.append("\r\n");

        builder.append("    卡片余额："+cmd.readBCD(3));
        builder.append("\r\n");

        return builder.toString();

    }
}
